clear all;
t = 1:100;
numSample = 100;

R2 = zeros(length(t),numSample);
for j = 1:numSample
    alphas = zeros(20,1);
    betas = zeros(20,1);
    fprintf(1,'#%d sample\n',j);
    for i = 2:length(t)
        [R2(i,j),alphas,betas] = solveR2(alphas,betas,0.2,[t(i-1),t(i)],0.01);
    end
end

save solveR2_data
%%
load solveR2_data
close all;
figure(1);
mean_R2 = mean(R2,2);
plot(t,mean_R2,'LineWidth',2);
set(gca,'FontSize',20);
xlabel('time(s)');
ylabel('mean(R^2)');
print('fig_mean_R2','-dpng');

figure(2);
var_R2 = var(R2,ones(1,numSample),2);
plot(t,var_R2,'LineWidth',2);
set(gca,'FontSize',20);
xlabel('time(s)');
ylabel('var(R^2)');
print('fig_var_R2','-dpng');